/*
 * (C) 2009, Elephant Seven Hamburg Gmbh, 
 * Author: Detlev Wiese
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 
 * use this file except in compliance with the License. You may obtain a copy 
 * of the License at
 *  
 *     http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.se and its accompanying notice file is
 * included with the distribution. 
 */ 
package com.e7.streams;


/**
 * <P>A stream class which is buffered: elements are internally grouped to 
 * collections of the given buffer size.</P>
 * <P>The buffered behavior will allow fast reading of all elements
 * which are held in the same buffer. At buffer bounds all elements 
 * of the next buffer will be retrieved from the underlying stream.</P>  
 * @param <E> The type of the elements of the resulting stream
 */
public class BufferedStream<E> extends ConcatenatedStream<E> {
	/**
	 * Create an instance!
	 * @param bufferSize The buffer size to use
	 * @param stream The stream to read into the buffers
	 */
	public BufferedStream(int bufferSize, Stream<E> stream) {
		super(new StreamOfStreams<E>(stream, bufferSize)); 
	}
	
	/**
	 * Syntactic sugar only.
	 * See {@link BufferedStream#BufferedStream(int, Stream)}. 
	 */
	public BufferedStream(Stream<E> stream, int bufferSize) {
		this(bufferSize, stream);
	}
}
